package com.example.comparable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

// map输出的key为待排序的flowbean  value为电话号码
public class FlowCountMapper extends Mapper<LongWritable, Text, FlowBean2, Text> {
    FlowBean2 k = new FlowBean2();
    Text v = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取一行 13509468723	7335	110349	117684
        String line = value.toString();
        // 截取
        String[] fields = line.split("\t");
        //封装对象
        String phoneNo = fields[0];
        long upFlow = Long.parseLong(fields[1]);
        long downFlow = Long.parseLong(fields[2]);
        long sumFlow = Long.parseLong(fields[3]);
        k.setUpFlow(upFlow);
        k.setDownFlow(downFlow);
        k.setSumFlow(sumFlow);
        v.set(phoneNo);
        context.write(k,v);
    }
}